package edu.je.column.controller;

import com.junqson.je.common.model.ApiResult;
import edu.je.column.model.ArticleIndexModel;
import edu.je.column.model.ArticleModel;
import edu.je.column.model.Vo.ArticleVo;
import edu.je.column.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author MengXin
 * @description:
 * @program: je-gateway
 * @date 2021/4/22 3:09
 * @mail mx@radish.cloud
 */
@RequestMapping("article")
@RestController
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @RequestMapping("getArticleById")
    public ApiResult getArticleById(@RequestParam(required = true) Long articleId){
        ArticleVo models = articleService.getArticleById(articleId);
        if (models==null){
            return ApiResult.error("查询失败");
        }
        return ApiResult.success(models);
    }

    @RequestMapping("getArticleIndex")
    public ApiResult getArticleIndex(@RequestParam(required = true) Long columnId){
        List<ArticleIndexModel>  models = articleService.getArticleIndex(columnId);
        if (models==null){
            return ApiResult.error("查询失败");
        }
        return ApiResult.success(models);
    }
}
